package rdgl.compiler;

import java.util.Random;

public abstract class Engine {

	private static Random rnd = new Random();
	private final static char[] letters = {
		'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
		'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
		'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
		'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
	};
	private final static char[] symbols = {
		'~', '!', '@', '#', '$', '%', '^', '&', '*', '*', '(', ')', '-',
		'+', '`', '_', '+', '<', '>', '/', '?', ',', '.', ':', ';', '"',
		'{', '}', '\\', '|', '[', ']', '=', '*',
	};
	
	/**
	 * Returns a single random number from [0,9] inclusive.
	 * @return single random number as string
	 */
	public static String getRandomNumber() {
		return getRandomNumber(1);
	}
	
	/**
	 * Returns a random number of the length specified.
	 * @param length
	 * @return random number as string
	 */
	public static String getRandomNumber(int length) {
		String value = new String();
		for(int i = 0; i < length; i++) {
			value += rnd.nextInt(10);
		}
		return value;
	}
	
	/**
	 * Returns a random number from [min, max] inclusive.
	 * @param min
	 * @param max
	 * @return random number as string
	 */
	public static String getRandomNumber(int min, int max) {
		int value = rnd.nextInt(max + 1 - min) + min;
		return value + "";
	}
	
	/**
	 * Returns a random character (regardless of case).
	 * @return single random character as string
	 */
	public static String getRandomCharacter() {
		return getRandomCharacter(1);
	}
	
	/**
	 * Returns a random character of the length specified.
	 * @param length
	 * @return random character(s) as string
	 */
	public static String getRandomCharacter(int length) {
		String value = new String();
		for(int i = 0; i < length; i++) {
			value += letters[rnd.nextInt(letters.length)];
		}
		return value;
	}
	
	/**
	 * 
	 * @return
	 */
	public static String getRandomAlphaNumeric() {
		return getRandomAlphaNumeric(1);
	}
	
	/**
	 * 
	 * @param length
	 * @return
	 */
	public static String getRandomAlphaNumeric(int length) {
		String value = new String();
		for(int i = 0; i < length; i++) {
			if(rnd.nextBoolean()) {
				value += getRandomCharacter();					
			} else {
				value += getRandomNumber();
			}
		}
		return value;
	}
	
	/**
	 * 
	 * @return
	 */
	public static String getRandomSymbol() {
		return getRandomSymbol(1);
	}
	
	/**
	 * 
	 * @param length
	 * @return
	 */
	public static String getRandomSymbol(int length) {
		String value = new String();
		for(int i = 0; i < length; i++) {
			value += symbols[rnd.nextInt(symbols.length)];
		}
		return value;
	}
	
	/**
	 * 
	 * @return
	 */
	public static String getRandomString() {
		return getRandomString(1);
	}
	/**
	 * 
	 * @param length
	 * @return
	 */
	public static String getRandomString(int length) {
		String value = new String();
		for(int i = 0; i < length; i++) {
			int index = rnd.nextInt(3); // [0, 1, 2]
			switch(index) {
				case 0: value += getRandomNumber();
					break;
				case 1: value += getRandomCharacter();
					break;
				case 2: value += getRandomSymbol();
					break;
			}
		}
		return value;
	}
}
